<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"
    import="java.sql.*"
 %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>acceuil</title>
</head>
<body>

 <%
Connection conn=null;
Statement stmt=null,stmt2=null,stmt3=null;
try{
	Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e){
	System.out.print("la classe est introuvale");
	e.printStackTrace();
	}
try{
	String url="jdbc:mysql://localhost:3306/base_labrocante";
	String user="root";
	String pw="";
	String titre=request.getParameter("t1");
	String cat=request.getParameter("t2");
	String ville=request.getParameter("t3");
	conn=DriverManager.getConnection(url,user,pw);
	stmt = conn.createStatement();
	stmt2 = conn.createStatement();
	stmt3 = conn.createStatement();
	String req1="select * from annonce where valider !=0 and titre like'%"+titre+"%' or categorie like '"+cat+"' or ville like '"+ville+"'";
	String req2="select * from ville";
	String req3="select * from categorie";
	ResultSet rset3=stmt3.executeQuery(req3);
	ResultSet rset2=stmt2.executeQuery(req2);
	ResultSet rset=stmt.executeQuery(req1);
	%>
<form name=f1 action=acceuil.jsp method="post">

<tableborder='1'>
<tr>
<td>Titre: </td><td><input type="text" name=t1></td>
<td>Categorie: </td>
			<td><select name=categorie>
			<option value=""></option>

	<% while(rset3.next())
	out.print("<option value='"+rset3.getString("nomCat")+"'>"+rset3.getString("nomCat")+"</option>");
	%>
</select></td>
<td>ville: </td>
			<td><select name=ville>
			<option value=""></option>

	<% while(rset2.next())
	out.print("<option value='"+rset2.getString("nomVille")+"'>"+rset2.getString("nomVille")+"</option>");
	%>
</select></td>
<td><input type="submit" value="Rechercher"></td>
</tr>
</table>
<table border="1">
		<tr>
			<th>Titre </th>
			<th>Annonce Description </th>
			<th>Telephone </th>
			<th>prix </th>
			<th>ville </th>
			<th>Categorie </th>
			<th >Vendeur</th>
		</tr>
		<%while(rset.next()){ %>
		<tr>
			<td><% out.print(rset.getString("titre"));%></td>
			<td><%out.print(rset.getString("texteAnnonce")); %></td>
			<td><%out.print(rset.getInt("tel")); %></td>
			<td><%out.print(rset.getFloat("prix")); %></td>
			<td><%out.print(rset.getString("ville")); %></td>
			<td><%out.print(rset.getString("categorie")); %></td>
			<td><%out.print(rset.getString("utilisateur")); %></td>
			
		</tr>
		<%} %>

<%
}
catch(SQLException e){
e.printStackTrace();
}
%>
</form>
</body>
</html>